import { useEffect, useState } from "react";
import { RouteObject } from "react-router-dom";
import { routeFilter } from "@/router/index.ts";
import { baseRouter } from "@/router/baseRouter.tsx";
import { useSelector } from "react-redux";

const useLoadRoutes = () => {
  const [routes, setRoutes] = useState(baseRouter as RouteObject[]);
  const user = useSelector((store: any) => store.user.userLevel);

  useEffect(() => {
    const newRoutes = routeFilter(baseRouter, user);
    setRoutes(newRoutes as RouteObject[]);
    return () => {};
  }, [user]);

  return routes;
};

export default useLoadRoutes;
